<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>CK宠物狗狗 领养  详情</title>
	<jsp:include page="top_utils.jsp"></jsp:include>
	<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/css/ly_art.css"/>
</head>
<body>
<!-- 头部-->
	<div class="headnav">
		<div class="topBar">
			<div class="topBarL">
				<jsp:include page="logo.jsp"></jsp:include>
				<div class="nav">
					<ul>
						<li >
							<a href="${pageContext.request.contextPath }/">首页</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/news/">新闻</a>
						</li>
						<li class="on">
							<a href="${pageContext.request.contextPath }/adopt/">领养</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/knowledge/">知识</a>
						</li>
						<li>
							<a href="${pageContext.request.contextPath }/dangdang/index.html">商城</a>
						</li>
					</ul>
				</div>
			</div>

			<jsp:include page="topBarR.jsp"></jsp:include>
		</div>
	</div>

	<!-- 中间内容-->
	<div class="wp">
		<div class="contents"> 
			<!--中间顶部-->
			<div class="con-top">
				
			</div>
			<!-- 中间内容 -->
			<div class="inner">
				<!--左边-->
				<div class="inner-left">
					<div class="innernews">
						<div class="bodys">
							<div class="news-top">
								<div class="t">
									<div class="l">
										<a href="${pageContext.request.contextPath }/adopt/">领养</a>
										<em>-›</em>
										<a href="#">${adopt.title }</a>
									</div>
								</div>
								<div class="b">
									
								</div>
							</div>
							<div class="news-other">
								<ul>
					              <li><a>共有${adopt.looknum }人围观</a></li>
					              <li><a>${adopt.remarknum }条评论</a></li>
					              <li style="float:right;"><a>发表时间：${adopt.uptime }</a></li>
					            </ul>
							</div>
							<input type="hidden" value="${adopt.id }" id="aid" />
							<div class="news-body">
								<h2>昵称：${adopt.petname } || 毛色:${adopt.petcolor } || ${adopt.petage }岁 </h2>
								<h2>地址：${adopt.address }</h2>
								${adopt.html }
							</div>
							<br/>
							<br/>
							<br/>
							<c:if test="${adopt.issend == 0 }">
								<c:if test="${adopt.isfortrue == 1 }">
									<div style="text-align: center;">
										<a class="layui-btn layui-btn-small"  href="javascript:">已被认领</a>
									</div>
								</c:if>
								<c:if test="${adopt.isfortrue == 0 }">
									<div style="text-align: center;">
										<input type="hidden" value="${sessionScope.user.id} id="recvid" />
										<a class="layui-btn layui-btn-small" id="${adopt.id }" onclick="send_sub(this.id)">申请认领</a>
									</div>
								</c:if>
							</c:if>
							<c:if test="${adopt.issend == 1 }">
								<div style="text-align: center;">
									<a class="layui-btn layui-btn-small"  href="javascript:">已被申请认领</a>
								</div>
							</c:if>
						</div>

						<!-- 评论区 -->
						<div class="conment">
							<div class="c-title"> 
							    <em>已有 ${adopt.remarknum } 人参与</em>
							    <h3>会员评论</h3>
						  	</div>
						  	<div class="c-ul">
						  			<div style="border: none;">
						  				<input type="hidden" id="uid" value="${user.id }"/>
						  				<input type="hidden" id="last_id" value="${adopt.id }"/>
						  				<input type="hidden" id="last_title" value="${adopt.title }"/>
						  				<textarea name="text" class="pt" id="r_content" autocomplete="off";>
						  					
						  				</textarea>
						  				<p class="pt10">
						  					<button  value="true" id="send_remark" class="sub">
						  						<strong>评论</strong>
						  					</button>
						  				</p>
						  			</div>

						  		<!-- 评论列表 -->
						  		<ul>
						  			<c:if test="${size == '0'}">
						  				<h1 style="font-size: 28px;">没有评论...</h1>
						  			</c:if>
						  			
						  			<c:if test="${size == '1'}">
						  				<c:forEach items="${remarklist }" varStatus="" var="remark"> 
						  					<li>
								  				<dl>
								  					<dt>
								  						<div class="portrait">
								  							<a href="javascript:">
								  								<img src="../images/client/ly/info/${remark.user.logoimg }">
								  							</a>
								  						</div>
								  						<a href="" class="username">${remark.user.username }</a>
								  						<span class="time">${remark.uptime }</span>
								  						<span class="guanzhu"> 
		                                                	<a href="javascript:;" onclick="dianzan()">点赞
		                                                	</a>
		      											</span>
								  					</dt>
								  					<dd>${remark.content }</dd>
								  				</dl>
								  			</li>
						  				</c:forEach>
						  			</c:if>
						  		</ul>
						  	</div>
						</div>
					</div>
				</div>
				
				<!--右边-->
				<div class="inner-right">
					<jsp:include page="remenyuedu.jsp"></jsp:include>					
					<!-- 广告 -->
					<div class="ad-1">
						<a href="" target="_blank">
							<img src="${pageContext.request.contextPath }/images/client/xw/ad-1.jpg" width="260">
						</a>
					</div>
				</div>
			</div>
		</div>
	</div>
	
	<jsp:include page="footer.jsp"></jsp:include>
</body>
<script type="text/javascript">
	$(document).ready(function (){
		$("#send_remark").on("click",function(){
			var uid = $("#uid").val();
			if(uid == "" || uid == null){
				layer.msg("你未登录!不能评论!",{shift:6});
				return false;
			}else{
				var content = $("#r_content").val();
				var last_id = $("#last_id").val();
				var user_id = uid;
				var last_title = $("#last_title").val();
				var key = "adopt";
				$.ajax({
		 			type:"post",
					url:"/dogstore/user/add_remark.action",
					async:false, 
		 			data:{
		 				content:content,
		 				user_id:user_id,
		 				last_id:last_id,
		 				last_title:last_title,
		 				key:key
		 			},
		 			success:function (error){
		 				if(error == "0"){
		 					layer.msg("评论成功!",{icon: 1,shift: 1});
		 					setTimeout(function (){
								//刷新
								window.location.reload();
							},1000);
		 				}else{
		 					layer.msg("评论失败!请联系prince!500",{icon: 2,shift: 6});
		 				}
		 			},
		 			error:function (){
		 				layer.msg("评论失败!请联系prince!",{icon: 2,shift: 6});
		 			} 			
		 		},"json");
			}
		});
	});
		
	//申请认领萌宠		
	function send_sub(id){
 		$.ajax({
 			type:"post",
			url:"/dogstore/adopt/send_adopt.action",
			async:false, 
 			data:{
 				id:id
 			},
 			success:function (error){
 				if(error == "0"){
 					layer.msg("申请成功!已加入领养单!",{icon: 1,shift: 1});
 					setTimeout(function (){
						//刷新
						window.location.reload();
					},1000);
 				}else if(error == "2"){
 					layer.msg("你未登录!",{icon: 2,shift: 6});
 				}else{
 					layer.msg("申请失败!请联系prince!500",{icon: 2,shift: 6});
 				}
 			},
 			error:function (){
 				layer.msg("申请失败!请联系prince!",{icon: 2,shift: 6});
 			} 			
 		},"json");
 	}
</script>
</html>